import { screenIndustryStructure } from '@/api/screen'

export default function useEnergyStructureAnalysis() {
  const data = ref<{ name: string, unit: string, value: string }[]>()

  const defaultNumber = inject<(m: any) => string>('defaultNumber')
  const getEnergyStructureAnalysis = async () => {
    try {
      const res = await screenIndustryStructure()
      data.value = (res.data.data || []).map((v: any) => ({
        ...v,
        value: defaultNumber ? defaultNumber(v.value) : v.value,
      }))
    }
    catch (e) {
      console.warn(e)
    }
  }

  return {
    data,
    getEnergyStructureAnalysis,
  }
}
